const http = require("http");
const fs = require("fs");
//客户端向服务端发送数据 
//在url中传递 不安全 数据过长 有限制

function sendPage(req, res) {
    let fileContent = fs.readFileSync("post.html");
    res.end(fileContent);
}

//POST向服务端发送数据
function postData(req, res) {
    let str = "";
    req.on("data", (chunk) => {
        str += chunk;
    })
    req.on("end", () => {
        console.log(str);
        //通过服务的响应到页面
        res.end("received post data " + str)
    })
}
http.createServer((req, res) => {
    switch (req.method) {
        case "GET":
            sendPage(req, res);
            break;
        case "POST":
            postData(req, res);
            break;
    }
}).listen(3000)
